﻿using System;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace FBGASaveData
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            string strCfgPath = string.Format("FBGASaveData.config");
            if (File.Exists(strCfgPath))
            {
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(strCfgPath);
                    foreach (XmlNode node in doc.DocumentElement)
                    {
                        if (node.Name == "DataReceive")
                        {
                            int.TryParse(node.Attributes["DataRecPort"].InnerText,out CGlobal.RecPort);
                        }
                        else if (node.Name == "DataSavePath")
                        {
                            string strFileSavePath=node.Attributes["FileSavePath"].InnerText;
                            if (Directory.Exists(strFileSavePath))
                            {
                                CGlobal.FilePath = strFileSavePath;
                            }
                        }
                        else if (node.Name == "DataFoward")
                        {
                            System.Net.IPAddress.TryParse(node.Attributes["ForwardIP"].InnerText, out CGlobal.FowardIP);

                            int.TryParse(node.Attributes["ForwardPort"].InnerText, out CGlobal.FowardPort);
                        }
                    }
                }
                catch { }
            }
            Application.Run(new frmSaveData());
        }
    }
}
